package com.apexedu.biz.service.impl;

import com.apexedu.framework.service.impl.AbstractBaseServiceSupport;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.framework.util.Pager;
import com.apexedu.identity.entity.TSysUser;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 *  所有用户管理
 * date:2013.10.10
 * user:liuxu
 */
@Service("userAccountManagerService")
public class UserAccountManagerServiceImpl extends AbstractBaseServiceSupport {
    
	@SuppressWarnings("unchecked")
	@Override
	public List<?> list(Object myaction, Pager pager) throws Exception {

        List<Object> params = new LinkedList<Object>();
        String sql = " from T_SYS_USER t where 1=1 ";

        /*if(project!=null){
            if(StringUtil.isNotBlank(project.getXmmc())){
                sql += " and t.xmmc like ?";
                params.add("%"+project.getXmmc()+"%");
            }
            if(StringUtil.isNotBlank(project.getSf())){
                sql += " and t.sf = ?";
                params.add(project.getSf());
            }*/

        long c = DBUtil.count("select count(*) as c " + sql, params.toArray());
		pager.setTotalRows(c);
        //hql.append(" order by ordernum desc");
        StringBuilder hql_column = new StringBuilder("select userid,userloginid,username,userpwd,(select departname from T_SYS_DEPART where departid=t.userdepart) as userdepart,state,(decode(t.usertype,'0','管理员',1,'业务管理')) as usertype,lastlogintime,logintimes,lastloginip ");
        hql_column.append(sql);
		List<TSysUser> list = DBUtil.queryPageBeanList(pager, hql_column.toString(), TSysUser.class, params.toArray());
		return list;
	}

    @Override
    public void saveOrUpdate(Object myaction) throws Exception {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void load(Object myaction) throws Exception {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean remove(Object myaction) throws Exception {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * 获取系统列表
     * @return
     */
    public List<Map<String,String>> systemList(){
        String sql = "select appid,appname from T_ACCESS_APP_REG";
        return DBUtil.queryForList(sql);
    }
}
